Manchester | 26-ITP-Jan | Farancis Dore Etonkie | Sprint 3 | Module Structuring and testing data#1216
Conversation
…ction. Added an example test case for right angles and a comment to indicate where to write additional tests. Also added explanations for the implementation of the isProperFraction function and the multiply function in the previous sprint.
cjyuan
left a comment
There was a problem hiding this comment.
-
Function implementation is correct.
-
Tests and test description could use some improvement.
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| // A proper fraction is a fraction where the absolute value of the numerator is less than the absolute value of the denominator. Additionally, the denominator cannot be zero. Therefore, we can check if the absolute value of the numerator is less than the absolute value of the denominator and if the denominator is not zero to determine if it is a proper fraction. |
There was a problem hiding this comment.
It's better to break a long comment into multiple lines so that we don't need to scroll horizontally in an editor to view all the comment.
There was a problem hiding this comment.
The tests in this script do not yet cover all cases.
| // Example: 1/2 is a proper fraction | ||
| test(`should return true for 1/2`, () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| }); | ||
| // Example: 2/1 is not a proper fraction | ||
| test(`should return false for 2/1`, () => { | ||
| expect(isProperFraction(2, 1)).toEqual(false); | ||
| }); | ||
| // Example: -1/2 is a proper fraction | ||
| test(`should return true for -1/2`, () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| }); | ||
| // Example: 1/-2 is a proper fraction | ||
| test(`should return true for 1/-2`, () => { | ||
| expect(isProperFraction(1, -2)).toEqual(true); | ||
| }); | ||
| // Example: -1/-2 is a proper fraction | ||
| test(`should return true for -1/-2`, () => { | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| }); |
There was a problem hiding this comment.
It is good that the selected test values cover all combinations of positive and negative values.
To make the tests clearer that all fractions that satisfy abs(numerator) < abs(denominator) are proper fractions, we could also express the test as:
test("should return true when abs(numerator) < abs(denominator)", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-1, -2)).toEqual(true);
});| test(`should return 10 for "J♦"`, () => { | ||
| expect(getCardValue("J♦")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`should return 10 for "Q♣"`, () => { | ||
| expect(getCardValue("Q♣")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`should return 10 for "K♠"`, () => { | ||
| expect(getCardValue("K♠")).toEqual(10); | ||
| }); |
There was a problem hiding this comment.
When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.
For example, one possible category for getCardValue() is, "should return 10 for face cards", and we can prepare the test as
test("should return 10 for face cards (J, Q, K)", () => {
expect(getCardValue("J♣︎")).toEqual(10);
expect(getCardValue("Q♠")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});
Can you practice preparing tests in this fashion?
| // Invalid Cards | ||
|
|
||
|
|
||
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror |
There was a problem hiding this comment.
Can you also implement this test? (Invalid case)
Learners, PR Template
Self checklist
Changelist